package com.woniuxy.kaer.service.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.kaer.commons.util.Result;
import com.woniuxy.kaer.service.entity.Consumables;
import com.woniuxy.kaer.service.from.AddConsumablesFrom;
import com.woniuxy.kaer.service.param.AddConsumablesParam;
import com.woniuxy.kaer.service.service.ConsumablesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 程诗洋
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/consumables")
@Api(tags = "消耗品接口")
public class ConsumablesController {
    @Resource
    private ConsumablesService consumablesService;
    @ApiOperation("添加耗材")
    @PostMapping("/AddConsumables")
    public Result AddConsumables(@RequestBody AddConsumablesFrom from)throws Exception{
        System.out.println(from.getServiceProjectId());
        AddConsumablesParam addConsumablesParam = BeanUtil.toBean(from, AddConsumablesParam.class);
        consumablesService.AddConsumables(addConsumablesParam);
        return Result.succeed("添加成功",null);
    }
    //根据服务项目Id，查询耗材信息
    @ApiOperation("根据服务项目Id，查询耗材信息")
    @GetMapping("/getConsumablesByServiceProjectId")
    public Result getConsumablesByServiceProjectId(@RequestParam("serviceProjectId")Integer serviceProjectId)throws Exception{
        List<Consumables> consumablesList = consumablesService.getConsumablesByServiceProjectId(serviceProjectId);
        return Result.succeed("查询成功",consumablesList);
    }


}

